package com.hgd.security.evp.auth.config;

import com.hgd.security.evp.auth.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author By 尚
 * @date 2019/3/30 14:31
 */
@Configuration
@Slf4j
public class BeanFactory {

    @Autowired
    private IUserService userService;

    @Bean
    public PasswordEncoder passwordEncoder(){
        log.debug("=====创建自定义PasswordEncoder=====");
        return new BCryptPasswordEncoder();
    }

//    @Bean
    public DaoAuthenticationProvider daoAuthenticationProvider(){
        DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
        daoAuthenticationProvider.setUserDetailsService(userService);
        return daoAuthenticationProvider;
    }
}
